package com.woniuxy.classteacher.uitility;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;


public class SendMessage {

    /**
     * @Author: 牟强
     * @Date: 2020/7/20/020 10:14
     * @Description: 发送通知学生密码已被初始化的消息验证码短信
     * @Param: [phoneNum, CodeNum]
     * @return: void
     **/
    public static void sendSms(String phoneNum, String CodeNum) {
//      这里去阿里申请密钥
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GCS479WvDDqMmWkVMeh", "SM85CMNHxEv09xB8apSEdkY6whcRdf");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
//        必填参数，手机号，签名，生成的验证码
        request.putQueryParameter("PhoneNumbers", phoneNum);
        request.putQueryParameter("SignName", "普通高级中学在线网");
        request.putQueryParameter("TemplateCode", "SMS_196618695");
//        短信内容
        request.putQueryParameter("TemplateParam", "{\"code\":\"" + CodeNum + "\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

}
